<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

    <!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap-theme.min.css" integrity="sha384-6pzBo3FDv/PJ8r2KRkGHifhEocL+1X2rVCTTkUfGk7/0pbek5mMa1upzvWbrUbOZ" crossorigin="anonymous">

</head>
<body>
<!--    <div style="height: 100px;background-color: red">-->
<!--        文字-->
<!--    </div>-->
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-4 col-sm-4 col-md-offset-4 col-sm-offset-4">
                <h1 class="text-center">欢迎使用岭南师范本系统</h1>
                <span id="error_span" style="color: red;" hidden></span>
                <form>
                    <div class="form-group">
                        <input type="email" name="email" class="form-control" placeholder="邮箱" required>
                    </div>
                    <div class="form-group">
                        <input type="password" name="password" class="form-control" placeholder="密码">
                    </div>
                    <div class="checkbox text-center">
                        <label>
                            <input type="checkbox"> 记住密码
                        </label>
                    </div>
                    <div class="form-group">
                        <!--login(this);this表示标签本身                        -->
                        <button type="button" onclick="login(event);" class="btn btn-primary btn-block">登录</button>
                    </div>
                    <div>
                        <button type="button" style="width: 49%" class="btn btn-primary">注册</button>
                        <button type="button" style="width: 49%" class="btn btn-primary">忘记密码</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
<!--bootstrap的JS是需要Jquery的支持-->
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<!--<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>-->
<script>
    function login(event) {
        console.log(event);
        // document.forms[0]
        let form = document.querySelector("form");
        let email = form["email"].value;
        let password = form["password"].value;
        let error_span = document.querySelector("#error_span");
        let errorMsg;
        if (email.trim().length === 0) {
            errorMsg = "邮箱不能为空!";
        }

        // if (!errorMsg && email.trim().length <= 6) {
        //     errorMsg = "邮箱至少6位";
        // }

        if (!errorMsg && password.length === 0) {
            // error_span.style.display = "inline-block";
            errorMsg = "密码不能为空!";
        }

        if (!errorMsg && password.length <= 6) {
            errorMsg = "密码至少6位";
        }

        if (errorMsg) {
            error_span.style.display = "inline-block";
            error_span.textContent = errorMsg;
            // return;//中断函数
        } else {
            //验证完成，提升登录的网络请求，由服务器验证邮箱和密码
            sessionStorage.setItem("email", email);
            //跳转
            window.location.href = "41-书本商城购物车-JS实现二.html";//相对路径和绝对路径都可以
        }
    }
</script>
</body>
</html>